import { Injectable } from '@nestjs/common';
import { OssService } from '../common/oss.service';
const path = require("path")
@Injectable() // @Injectable修饰后的 AppService, 在AppModule中注册之后，在app.controller.ts中使用，我们就不需要使用new AppService()去实例化，直接引入过来就可以用
export class AppService {
  constructor(private readonly ossService: OssService) {}
  getHello(): string {
    return 'Hello World nestjs!';
  }

  async uploadFile(file: any): Promise<any> {
    try {
      const ossUrl = await this.ossService.putOssFile(
        `/uploadImage/${file.originalname}`,
        `C:/Users/Administrator/Desktop/图片/${file.originalname}`,
      );
      return {
        imgUrl: ossUrl
      };
    } catch (error) {
      return {
        code: 503,
        msg: `Service error: ${error}`,
      };
    }
  }
}
